#include "taxipanel.h"
#include "qpainter.h"

TaxiPanel::TaxiPanel(QWidget* parent):
    QWidget(parent)
{

}

void TaxiPanel::paintEvent(QPaintEvent *)
{
    int width = this->width();
    int height = this->height();
    QPainter painter(this);
    painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
    painter.translate(width/2, height/2);
    int side = qMin(width, height);
    painter.scale(side / 200.0, side / 200.0);

    drawRoadCurb(&painter);
    drawMidLine(&painter);
    drawPlane(&painter);
}

void TaxiPanel::drawRoadCurb(QPainter *painter)
{
    painter->save();
    QPen pen;
    pen.setColor(QColor(255,255,255,255));
    pen.setWidthF(7.0);
    painter->setPen(pen);
    painter->drawLine(-80,-100,-80,100);
    painter->drawLine(80,-100,80,100);
    painter->restore();
}

void TaxiPanel::drawPlane(QPainter *painter)
{
    painter->save();
    painter->translate(this->dz*4,60);
    painter->rotate(this->dpsi);
    //painter->translate(this->dz,0);
    QPixmap pixmap(":/pic/plane.png");
    QRectF target(-40.0, -22.0, 80.0, 44.0);//QRectF target(0.0, 0.0, 80.0, 44.0);
    QRectF source(0.0, 0.0, pixmap.width(), pixmap.height());
    painter->drawPixmap(target, pixmap,source);
    painter->restore();
}

void TaxiPanel::drawMidLine(QPainter *painter)
{
    painter->save();
    QPen pen;
    pen.setColor(QColor(244,177,131,255));
    pen.setWidthF(5.0);
    painter->setPen(pen);
    float vd = this->vd;
    float up = -100+vd;
    float dp = -40+vd;
    if(dp>100)
    {
        dp-=200;
        painter->drawLine(0,-100,0,dp);
        painter->drawLine(0,up,0,100);
    }
    else
        painter->drawLine(0,up,0,dp);

    up = 0+vd;
    dp = 60+vd;
    if(dp>100)
    {
        dp-=200;
        painter->drawLine(0,-100,0,dp);
        painter->drawLine(0,up,0,100);
    }
    else
        painter->drawLine(0,up,0,dp);
/*
    up = 0+vd;
    dp = 30+vd;
    if(dp>100)
    {
        dp-=200;
        painter->drawLine(0,-100,0,dp);
        painter->drawLine(0,up,0,100);
    }
    else
        painter->drawLine(0,up,0,dp);

    up = 50+vd;
    dp = 80+vd;
    if(dp>100)
    {
        dp-=200;
        painter->drawLine(0,-100,0,dp);
        painter->drawLine(0,up,0,100);
    }
    else
        painter->drawLine(0,up,0,dp);*/

    painter->restore();
}

void TaxiPanel::setTaxiValue(float dpsi,float dz,float vd)
{
    this->dpsi = dpsi;
    this->dz = dz;
    this->vd = vd;
}
